/*
 * table_CcBlockNest_t.c
 *
 *  Created on: 2012-5-14
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"
typedef struct _CCBLOCKNEST{
	AST astLabelChain;
	AST astSymChain;
	AST astTagChain;
	BOOL bDeclFinished;
}BLOCKNEST, *PBLOCKNEST;

#define TableSize  (sizeof(BLOCKNEST))
#define TableType  PBLOCKNEST
#define stTable (stBlockNestManager.memoryBlocks)
#define maxTable (stBlockNestManager.maxRecordNum)
#define  maxNumPerBlk  (stBlockNestManager.astMaxNum_Block)


/* get the object */
static TABLEMANAGER stBlockNestManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stBlockNestManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stBlockNestManager, resetListener, index );
	if( temp != NULL ){
		if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
	}
	return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stBlockNestManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stBlockNestManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stBlockNestManager, astReqArg, resetListener );
}

static AST getMaxLineNum( VOID )
{
	return maxTable;
}

static AST getTagRoot( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTagChain;
}
static AST setTagRoot( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTagChain = value;
}
static AST getLabelRoot( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLabelChain;
}
static AST setLabelRoot( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLabelChain = value;
}
static AST getSymbolRoot( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSymChain;
}
static AST setSymbolRoot( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSymChain = value;
}
static BOOL isDeclListFinished( AST index ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return FALSE;
	}
	return pTbl->bDeclFinished;
}
static BOOL setDeclListFinished( AST index, BOOL Value ){
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return FALSE;
	}
	return pTbl->bDeclFinished = Value;
}
const BLOCKNESTACCESS stBlockNestAccess ={
		//		BOOL (*clear)( VOID );
				ClearTable,
		//		BOOL (*reset)( VOID );
				ResetTable,
		//		BOOL (*alloc)( AST );
				AllocTable,
		//		AST  (*getMax)( VOID );
				getMaxLineNum,
				{
						getTagRoot,
						setTagRoot
				},
				{
						getLabelRoot,
						setLabelRoot
				},
				{
						getSymbolRoot,
						setSymbolRoot
				},
				{
						isDeclListFinished,
						setDeclListFinished
				}
};
